#include "viewer.h"


namespace mesh
{


viewer::viewer(QWidget* parent)
  : QGLWidget(parent)
{

}

void viewer::initializeGL(void)
{

}

void viewer::paintGL(void)
{

}

void viewer::resizeGL(int width, int height)
{

}


void viewer::draw(void)
{
  for (mesh_color_mapper const* m : _meshes)
  {
    glBegin(GL_TRIANGLES);

    for (unsigned i = 0; i < m->faces().size(); ++i)
    {
      for (unsigned id : m->faces()[i].get_indices())
      {
        glColor3fv(
              reinterpret_cast<float const*>(
                &m->vertices_colors()[id]));
        glVertex3fv(
              reinterpret_cast<float const*>(
                &m->vertices()[id]));
      }
    }

    glEnd();
    glBegin(GL_LINES);

    for (unsigned i = 0; i < m->edges().size(); ++i)
    {
      for (unsigned id : m->edges()[i].get_indices())
      {
        glColor3fv(
              reinterpret_cast<float const*>(
                &m->vertices_colors()[id]));
        glVertex3fv(
              reinterpret_cast<float const*>(
                &m->vertices()[id]));
      }
    }

    glEnd();
    glBegin(GL_POINTS);

    for (unsigned i = 0; i < m->vertices().size(); ++i)
    {
      glColor3fv(
            reinterpret_cast<float const*>(
              &m->vertices_colors()[i]));
      glVertex3fv(
            reinterpret_cast<float const*>(
              &m->vertices()[i]));
    }

    glEnd();
  }
}


} // mesh
